<?php
/**
 * http请求参数(get和post)
 *
 * @author vincent
 *        
 */
class Input {
	/**
	 * input实例
	 *
	 * @var Input
	 */
	private static $input = NULL;
	/**
	 * 请求中的所有参数
	 *
	 * @var array
	 */
	protected $params = array ();
	/**
	 * 构造函数
	 */
	private function __construct() {
		$this->params = array_merge ( $_GET, $_POST ); // 合并get和post请求的参数
	}
	/**
	 * 创建input实例
	 */
	public static function getInstance() {
		if (self::$input == NULL) {
			self::$input = new Input ();
		}
		return self::$input;
	}
	/**
	 * 获取参数的值
	 *
	 * @param string $name
	 * @return multitype:
	 */
	public function get($name) {
		$num = func_num_args ();
		if ($num == 1 && isset ( $this->params [$name] )) {
			return $this->params [$name];
		}
		else if ($num > 1) {
			$list = func_get_args ();
			$data = array ();
			foreach ( $list as $key ) {
				$data [] = isset ( $this->params [$key] ) ? $this->params [$key] : NULL;
			}
			return $data;
		}
		return null;
	}
	/**
	 * 判断参数是否存在
	 *
	 * @param string|array $name
	 * @return bool
	 */
	public function has($name) {
		if (is_string ( $name ) && isset ( $this->params [$name] )) {
			return true;
		}
		if (is_array ( $name )) {
			foreach ( $name as &$key ) {
				if (! isset ( $this->params [$key] )) {
					return false;
				}
			}
			return true;
		}
		return false;
	}
	/**
	 * 获取所有参数
	 *
	 * @return multitype:
	 */
	public function getParams() {
		return $this->params;
	}
}